import React, { Component } from 'react';
// import IceContainer from '@icedesign/container';
import { Menu,Nav } from '@icedesign/base';
import { Link, withRouter } from 'react-router-dom';
import axios from 'axios';
import './YuJingSecondNav.scss';

const { Item } = Nav;

@withRouter
export default class YuJingSecondNav extends Component {
  static displayName = 'TabTable';

  static propTypes = {};

  static defaultProps = {};

  constructor(props) {
    super(props);
    // console.log("secondnav",props)
    this.state = {
      tabs: [],
      tabName:'',
      activeKey: 1,
      superUser:false
    };
  }

  componentDidMount() {
    // if(this.GetUrlParam("sid")){
    //   this.setState({
    //     activeKey:this.GetUrlParam("sid")
    //   })
    // }
    this.GetUrlString();
    this.checkAuthor(this.GetUrlParam("secu_code"))
    // console.log("GetUrlParam-sid",this.GetUrlParam("sid"))
  }

  GetUrlString(paraName) {
    　var url = document.location.toString();
      if(url.indexOf("gdBeta2.0/#/earlyWarning/CreditRisk")!=-1){
        this.setState({
        activeKey:1
        })
      }else if(url.indexOf("gdBeta2.0/#/earlyWarning/PublicOpinionWarning")!=-1){
        this.setState({
          activeKey:2
        })
      }else{
        return "/"
      }
    }

  GetUrlParam(paraName) {
  　var url = document.location.toString();
  　var arrObj = url.split("?");
  　　　if (arrObj.length > 1) {
  　　　　　var arrPara = arrObj[1].split("&");
  　　　　　var arr;
  　　　　　for (var i = 0; i < arrPara.length; i++) {
  　　　　　　　arr = arrPara[i].split("=");
  　　　　　　　if (arr != null && arr[0] == paraName) {
  　　　　　　　　　return arr[1];
  　　　　　　　}
  　　　　　}
  　　　　　return "";
  　　　}
  　　　else { return ""; }
  }

  handleChange = (key) => {
    // console.log("key",key)
    localStorage.setItem("sid",key)
    this.setState({
      activeKey: key,
    });
    if(key==0){
      window.location.href = `${global.constants.GOLDEYELOCALHOST}gdBeta2/#/earlyWarning/creditRisk?secu_code=${this.GetUrlParam("secu_code")}`
    }else if(key==1){
      window.location.href = `${global.constants.GOLDEYELOCALHOST}gdBeta2/#/earlyWarning/opWarning/shortAnswerB?secu_code=${this.GetUrlParam("secu_code")}`
      // this.props.history.push(`/earlyWarning/CreditRisk?sid=1&secu_code=${this.GetUrlParam("secu_code")}`)
      // window.location.href = "/earlyWarning/CreditRisk?tid=3&machineCode=000000111"
    }else if(key==2){
      window.location.href = `${global.constants.GOLDEYELOCALHOST}gdBeta2/#/earlyWarning/opWarning/shortAnswerB?secu_code=${this.GetUrlParam("secu_code")}`
    }else if(key==3){
      // this.props.history.push(`/earlyWarning/PublicOpinionWarning?sid=3&secu_code=${localStorage.getItem("TOKEN")}`)
      window.location.href = `https://eye.cfbond.com/sina/yqyj?secu_code=${this.GetUrlParam("secu_code")}`
    }else if(key==4){
      // this.props.history.push(`/earlyWarning/PublicOpinionWarning?sid=3&secu_code=${localStorage.getItem("TOKEN")}`)
      window.location.href = `${global.constants.GOLDEYELOCALHOST}gdBeta2.0/#/earlyWarning/OpinionRisk?secu_code=${this.GetUrlParam("secu_code")}`
    }else if(key==5){
      // this.props.history.push(`/earlyWarning/PublicOpinionWarning?sid=3&secu_code=${localStorage.getItem("TOKEN")}`)
      window.location.href = `${global.constants.GOLDEYELOCALHOST}gdBeta2.0/#/earlyWarning/Supervise?secu_code=${this.GetUrlParam("secu_code")}`
    }
  };

  //获取是否超级用户
  checkAuthor(sc){
    // console.log(sc)
    axios.get(`${global.constants.GOLDEYEGETHOST}cattle/get_account_type?secu_code=${sc}`)
      .then(data => {
        // console.log("用户等级1",data.data.data.is_super_account)
        // if(data.data.flag){
          this.setState({
            superUser: data.data.data.is_super_account
          },() => {
            // localStorage.setItem("superUser",data.data.data.is_super_account)
            console.log("超级用户",data.data.data.is_super_account)
          })
        // }
    })
    .catch(function (error) {
        console.log(error);
    });
  }

  render() {
    return (
      <div className="second-menu">
      <Nav 
        direction="hoz"
        prefix="second"
        // selectMode="multiple"
        // defaultSelectedKeys={[this.state.activeKey]}
        selectedKeys={[`${this.state.activeKey}`]}
        onSelect={this.handleChange.bind(this)}
      >
        <Item prefix="second-" key={0}>
          信披风险
        </Item>

        <Item prefix="second-" key={1}>
          经营预警
        </Item>
        
        <Item prefix="second-" key={2}>
          市值预警
        </Item>

        <Item prefix="second-" key={3}>
          舆情预警
        </Item>

        {/* <Item prefix="second-" key={4}>
          风险预警
        </Item>

        <Item prefix="second-" key={5}>
          监管风险
        </Item> */}
        
      </Nav>
      </div>
    );
  }
}

